/*  
	This JS document is developed by Martin Chen
*/

        /*check all input controls and if there is anyone invalid return false*/
		function validateForm(){			
			
			var validationResult = true;		
			if(!checkImageName()){
					validationResult = false;
				}							
			if(!checkWidth()){
					validationResult = false;
				}								
			if(!checkHeight()){
					validationResult = false;
				}								
			return validationResult;			
		}
		
		
		function checkImageName(){
			var obj = document.getElementById("imageFileName").value;		
			if (obj == null ||obj == "") {
					document.getElementById("imageFileNameAlert").style.visibility = "visible";//if not value entered
					return false;//results in false				
			   }			   
		 	var patt = /^.*\.(jpg|gif|png|bmp)$/i;      //check image file format
			if(!patt.test(obj)){				
					document.getElementById("imageFileNameAlert").style.visibility = "visible";
					return false;				
			   }			   
			document.getElementById("imageFileNameAlert").style.visibility = "hidden";  
			return true;			
		}	
		
	
		function checkWidth(){
			var obj = document.getElementById("width").value;	//checks for the given name field		
			if (obj == null ||obj == "") {
									document.getElementById("widthAlert").style.visibility = "visible";//if not value entered
					return false;//results in false				
			   }			   
		 	var patt = /^[1-9]\d*$/;//check number input
			if(!patt.test(obj)){				
					document.getElementById("widthAlert").style.visibility = "visible";
					return false;				
			   }			   
			document.getElementById("widthAlert").style.visibility = "hidden";  
			return true;			
		}	
		
				
		
		function checkHeight(){			
			var obj = document.getElementById("height").value;//checks for email address format			
			if (obj == null || obj == "") {				
					document.getElementById("heightAlert").style.visibility = "visible";
					return false;					
			   }			   		 	
			/*using regular expression to verify if user type valid date format*/
			var patt=/^[1-9]\d*$/;
			if(!patt.test(obj)){				
					document.getElementById("heightAlert").style.visibility = "visible";
					return false;				
			   }			   
			document.getElementById("heightAlert").style.visibility = "hidden";
			return true;			
		}
		
		
		
	
		
		